#include <cstdio>
#include <cstring>

#define MAXN 1005

int N;
double H[MAXN];
double LCS[MAXN];

int bsearch(double h, int start, int end) {
    int left = start;
    int right = end-1;
    while (left < right) {
        int mid = (left+right) / 2;
        if (h > LCS[mid]) {
            left = mid+1;
        } else {
            right = mid;
        }
    }
    return left;
}

int lcs(int start, int end) {
    int len = 1;
    LCS[len] = H[start];
    for (int i=start+1; i<end; i++) {
        if (H[i] > LCS[len]) {
            LCS[++len] = H[i];
        } else {
            int k = bsearch(H[i], 1, len+1);
            LCS[k] = H[i];
        }
    }
    return len;
}

int lds(int start, int end) {
    int len = 1;
    LCS[len] = H[end-1];
    for (int i=end-2; i>=start; i--) {
        if (H[i] > LCS[len]) {
            LCS[++len] = H[i];
        } else {
            int k = bsearch(H[i], 1, len+1);
            LCS[k] = H[i];
        }
    }
    return len;
}

int main()
{
    int ans = 0;
    scanf("%d", &N);
    for (int i=0; i<N; i++) {
        scanf("%lf", &H[i]);
    }
    for (int i=0; i<N-1; i++) {
        int a = lcs(0, i+1);
        int b = lds(i+1, N);
        if (a+b > ans)
            ans = a+b;
    }
    printf("%d\n", N-ans);
    return 0;
}
